home *** CD-ROM | disk | FTP | other *** search
- // Chap19_3.cpp
- // This is not a complete program. Compare this solution with
- // Chap19_2 which uses RTTI.
- class Account
- {
- public:
- Account(int accNo, float initialBalance);
-
- virtual void deposit(float amount);
- virtual void withdrawal(float amount);
-
- // addInterest - the default addInterest does nothing
- virtual void addInterest()
- {
- }
-
- // addAccount - add current account to the account list
- void addAccount();
-
- // getNext - get the next account from the account list;
- // if pPrev == 0, return first;
- // return 0 when no more left in list
- static Account* getNext(Account *pPrev);
- };
-
- class Checking : public Account
- {
- public:
- Checking(int accNo, float initialBalance = 0.0F) ;
- };
-
- class Savings : public Account
- {
- public:
- Savings(int accNo, float initialBalance = 0.0F);
-
- // addInterest - calculate the interest for one time
- // period and add it back in
- void addInterest();
- };
-
- // accInterest - loop thru the accounts. For each Savings
- // account you find, calculate the interest and
- // it back in
- void accInterest()
- {
- // loop thru the Accounts
- Account* pA = (Account*)0;
- while(pA = Account::getNext(pA))
- {
- // so add the interest in
- pA->addInterest();
- }
- }
-